package org.yannis.app.app1.client;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author Yannis Zhao, 2019/1/10.
 * @since 1.0
 */
public final class SnailUtils {

    private SnailUtils() {
    }

    public static final String getUsername() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return (principal instanceof UserDetails) ? ((UserDetails) principal).getUsername() : principal.toString();
    }

}
